/**
 * This file is part of decent-cpp.
 *
 * decent-cpp is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * decent-cpp is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with decent-cpp.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once
#include <nlohmann/json.hpp>
#include <server_wss.hpp>
#include "crypto.h"

#ifdef USE_HTTPS
using WsMode = SimpleWeb::WSS;
#else
using WsMode = SimpleWeb::WS;
#endif
typedef SimpleWeb::SocketServer<WsMode> WsServer;

namespace dc {
namespace Event {
const std::string pingdata("pingdata");
const std::string pongdata("pongdata");
const std::string serversettings_update("server-settings/update");
#define EVT(x, y) const std::string x##_##y(#x "/" #y)
#define EVT2(x, y, z) const std::string x##_##y##_##z(#x "/" #y "/" #z)
EVT(message, new);
EVT(message, edit);
EVT(message, delete);
EVT(channel, new);
EVT(channel, update);
EVT2(channel, pins, add);
EVT2(channel, pins, remove);
EVT(channel, delete);
EVT(user, new);
EVT(user, delete);
EVT(user, online);
EVT(user, offline);
EVT(user, update);
EVT2(user, mentions, add);
EVT2(user, mentions, remove);
EVT(emote, new);
EVT(emote, delete);
EVT(role, new);
EVT(role, update);
EVT(role, delete);
#undef EVT2
#undef EVT
}  // namespace Event
/// Starts the websocket server
void server_ws_init();
/// Stops the websocket server
void server_ws_kill();
/// Upgrades a connection
void server_ws_upgrade(const std::shared_ptr<WsServer::Connection>&);
/// Broadcast a message to everyone
void server_ws_broadcast(std::string evt, nlohmann::json& json);
/// Send a message to a specific session
void server_ws_send(std::string evt, nlohmann::json& json, uuid session);
}  // namespace dc